/**
 * Created by DELL on 2016/12/22.
 */
/**
 * @param {number[]} prices
 * @return {number}
 */
var prices = [7, 1, 5, 3, 6, 4]
var maxProfit = function(prices) {
    var len = prices.length;
    var start = 0;
    var max = 0;
    var profit = 0;
    for(var i = 1;i < len;i++){
        profit = prices[i]-prices[start];
        if(profit > max){
            max = profit;
        }
        if(prices[i] < prices[start]){
            start = i;
        }
    }
    return max;
};
console.log(maxProfit(prices));